package 迭代器模式;

import sun.util.locale.provider.FallbackLocaleProviderAdapter;
import 迭代器模式.接口.Goods;
import 迭代器模式.接口.MyIterator;

public class GoodsImpl implements Goods {
    protected String [] goods={"手机","电脑","短袖","ipad"};


    @Override
    public MyIterator getMyIterator() {
        return new MyIteratorImpl();
    }

    /**
     * 内部类（迭代器实现类）
     */
    class MyIteratorImpl implements MyIterator {
        private int currentGoods=0;

        public void first() {
            currentGoods=0;
        }

        //是否有下一个
        public boolean hasNext() {
            if (currentGoods<goods.length) {
                return true;
            }else {
                return false;
            }
        }
        //指向下一个
        public void next() {
            if (hasNext()){
                currentGoods++;
            }
        }

        //指向最后一个
        @Override
        public void lasst() {
            currentGoods=goods.length-1;
        }

        public boolean hasPri() {
            if (currentGoods>=0) {
                return true;
            }else {
                return false;
            }
        }

        public void pri() {
            if (hasPri()){
                currentGoods--;
            }
        }
        public String getCurrent(){
            return goods[currentGoods];
        }

    }
}
